﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>StrCompare - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The StrCompare function compares two strings alphabetically." />
<meta name="ahk:equiv-v1" content="AutoHotkey.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css">
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>StrCompare</h1>
<p>按字母顺序比较两个字符串.</p>
<pre class="Syntax">Result := <span class="func">StrCompare</span>(String1, String2 <span class="optional">, CaseSensitive := false</span>)</pre>

<h2 id="Parameters">参数</h2>
<dl>
  <dt>String1, String2</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>要比较的字符串.</p>
  </dd>
  <dt>CaseSensitive</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
    <p>如果参数 <em>CaseSensitive</em> 被省略或为 0(false), 则比较不区分大小写(不区分的方法取决于 <a href="StringCaseSense.htm">StringCaseSense</a>); 否则, 大小写必须完全匹配, 才能认为字符串是相同的.</p>
  </dd>
</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>指示 <em>String1</em> 和 <em>String2</em> 之间的关系, 该函数返回以下内容之一:</p>
<ul>
  <li>0, 如果 <em>String1</em> 等于 <em>String2</em></li>
  <li>1, 如果 <em>String1</em> 大于 <em>String2</em></li>
  <li>-1, 如果 <em>String1</em> 小于 <em>String2</em></li>
</ul>

<h2 id="Remarks">备注</h2>
<p>此函数通常用于 <a href="Sort.htm#callback">sort 回调</a>.</p>

<h2 id="Related">相关</h2>
<p><a href="StringCaseSense.htm">StringCaseSense</a>, <a href="Sort.htm">Sort</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>
MsgBox StrCompare("Abc", "abc") <em>; 返回 0</em>
MsgBox StrCompare("Abc", "abc", true) <em>; 返回 -1</em>
</pre>
</div>

</body>
</html>